package cn.javaxc.mvcwork.modules.admin;
import cn.javaxc.mvcwork.framework.actions.TActionContext;
import cn.javaxc.mvcwork.util.common.*;
import java.io.File;
import org.w3c.dom.Element;
import cn.javaxc.mvcwork.controller.Template;



public class UserEmail {
  private String subject = null;
  private String body = null;


  
  public String getSubject() {
    return subject;
  }


  
  public void setSubject(String tmp) {
    this.subject = tmp;
  }


  
  public String getBody() {
    return body;
  }


  
  public void setBody(String tmp) {
    this.body = tmp;
  }


  
  public UserEmail(TActionContext context, User thisUser, String name, String password, String url, String templateFile) throws Exception {
    // Load the templates
    File configFile = new File(templateFile);
    XMLUtils xml = new XMLUtils(configFile);
    Element mappings = xml.getFirstChild("mappings");
    // Construct the subject
    Template messageSubject = new Template();
    messageSubject.setText(
        XMLUtils.getNodeText(
            XMLUtils.getElement(mappings, "map", "id", "newuser.alert.email.subject")));
    messageSubject.addParseElement("\r\n", "");
    messageSubject.addParseElement("\r", "");
    messageSubject.addParseElement("\n", "");
    subject = messageSubject.getParsedText();
    // Construct the body
    Template messageBody = new Template();
    messageBody.setText(
        XMLUtils.getNodeText(
            XMLUtils.getElement(
                mappings, "map", "id", "newuser.alert.email.body")));
    messageBody.addParseElement("${user.username}", thisUser.getUsername());
    messageBody.addParseElement("${user.password}", password);
    if (name != null) {
      messageBody.addParseElement("${modUserName}", name);
    } else {
      messageBody.addParseElement("${modUserName}", "the administrator");
    }
    messageBody.addParseElement("${url}", url);
    messageBody.addParseElement("${endUrl}", "</a>");
    body = messageBody.getParsedText();
  }
}
